<?php

/***

LZRoster: A roster for World of Warcraft.
Copyright (C) 2007  Emmanuel Cron

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

***/

require_once dirname(__FILE__)."/SessionRoster.class.php";

class Object_
{
	static private $session_roster;
	
	private $unique_id = null;
	private $item_id;
	private $spell_id;
	private $color;
	private $texture;
	
	private $names = array();
	private $tooltips = array();
	
	private $missing_tooltip = false;
	
	function Object_($t)
	{
		if ( empty(self::$session_roster) )
		{
			self::$session_roster = SessionRoster::GetInstance();
		}
		
		$this->item_id = array_key_exists('ItemId', $t) ? $t['ItemId'] : null;
		$this->spell_id = array_key_exists('SpellId', $t) ? $t['SpellId'] : null;
		$this->color = $t['Color'];
		$this->texture = $t['Texture'];
		
		$locales = explode(",", $t['Locales']);
		$names = explode(",", $t['Names']);
		$tooltips = explode("_\$_", $t['Tooltips']);
		
		while ( $locale = current($locales) )
		{
			$this->names[$locale] = current($names);
			
			if ( current($tooltips) == null )
			{
				$this->missing_tooltip = true;				
			}
			else
			{
				$this->tooltips[$locale] = current($tooltips);
			}
			
			next($locales);
			next($names);
			next($tooltips);
		}
	}
	
	function HasMissingTooltip()
	{
		return $this->missing_tooltip;
	}
	
	function GetItemId()
	{
		return $this->item_id;
	}
	
	function GetSpellId()
	{
		return $this->spell_id;
	}
	
	function GetTexture()
	{
		return str_replace("\\\\", "/", $this->texture);
	}
	
	function GetColor()
	{
		return $this->color;
	}
	
	function HasNameThisLocale()
	{
		return array_key_exists(self::$session_roster->GetLocalization(), $this->names);
	}
	
	function GetNameThisLocale()
	{
		return $this->names[self::$session_roster->GetLocalization()];
	}
	
	function GetNameLocale($locale)
	{
		return $this->names[$locale];
	}
	
	function HasTooltipThisLocale()
	{
		return array_key_exists(self::$session_roster->GetLocalization(), $this->tooltips);
	}
	
	function HasTooltipLocale($locale)
	{
		return array_key_exists($locale, $this->tooltips);
	}
	
	function GetTooltipThisLocale()
	{
		return $this->tooltips[self::$session_roster->GetLocalization()];
	}
	
	function GetTooltipLocale($locale)
	{
		return $this->tooltips[$locale];
	}
	
	function GetTooltipAll()
	{
		return $this->tooltips;
	}
}

?>